package com.mycompany.lctwitter.persist.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.mycompany.lctwitter.persist.dao.MessageDao;
import com.mycompany.lctwitter.persist.model.Message;

@Service("messageService")
@Transactional(readOnly = true, propagation = Propagation.NOT_SUPPORTED, rollbackFor = Exception.class)
public class MessageService {

    @Resource
    private MessageDao messageDao;

    @Transactional
    public void addMessage(long userId, String message, long locationId) {
        messageDao.add(userId, message, locationId);
    }

    @Transactional
    public void deleteMessage(long messageId) {
        messageDao.delete(messageId);
    }

    public List<Message> listByUser(long userId) {
        return messageDao.listByUser(userId);
    }

    public List<Message> listByUserAndLocation(long userId, long locationId) {
        return messageDao.listByUserAndLocation(userId, locationId);
    }

    public List<Message> listByLocation(long locationId) {
        return messageDao.listByLocation(locationId);
    }
}
